<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib prefix="shiro"  uri="http://shiro.apache.org/tags"%>
<style>
	.scheduleBox{width:400px; height:auto}
</style>
<script>
$(function(){
	$('.date-picker').datepicker({
		autoclose: true,
		todayHighlight: true
	}).next().on(ace.click_event, function(){
		$(this).prev().focus();
	});
	
	var datatable = $("#RoleTable").DataTable({
		"language":{
			"url": "${pageContext.request.contextPath}/resources/admin/assets/de_DE.txt"
		},
		"dom": '<"top" >rt<"bottom" ifp><"clear">',
		"lengthMenu": [10, 3, 20,30],
		"pagingType": "full_numbers",
		"order":[[3,'asc']],
		"filter": false,
		"processing": true,
		"serverSide": true,
		"ajax": {
            "url": "${pageContext.request.contextPath}/sys/role/roleList.do",
            "type": "post",
			"data" : function(d){
				d.username = $('#username').val();
				d.acttime = $('#acttime').val();
				d.addtime = $('#addtime').val();
			}            
        },
		 "columns": [
		        {"data":"id","sortable":false,"render":function(data,type,row){
		        	return '<input type="checkbox" class="ace" value="'+row.id+'"/> <span class="lbl"></span>'
		        },"class":"center","width":"10px"},
				{ "data": "rolename" },
				{"data": "remark"},
				{ "data": "seq" },
				{ "data": null,orderable: false,"width":"200","render":function(data,type,row){
					return   '<a href="#" class="blue" onclick="viewResources('+row.id+')"><i class="ace-icon fa fa-eye"></i>查看资源</a>'+'<shiro:hasPermission name="sys:role:edit">&nbsp;&nbsp;<a href="#" class="green" onclick="editRole('+row.id+')"><i class="ace-icon fa fa-pencil"></i>编辑角色</a></shiro:hasPermission>'+ '<shiro:hasPermission name="sys:role:del">&nbsp;&nbsp;<a href="#" class="red" onclick="delRole('+row.id+')"><i class="ace-icon fa fa-trash-o "></i>删除角色</a></shiro:hasPermission>';
				}} 
	        ]
	});
	
	$('#doSearch').click(function(){
		datatable.draw();
	});
	
	$(document).on('click', 'th input:checkbox' , function(){
		var that = this;
		$(this).closest('table').find('tr > td:first-child input:checkbox')
		.each(function(){
			this.checked = that.checked;
			//$(this).closest('tr').toggleClass('selected');
		});
	});
});
function viewResources(roleId){
	var url = "${pageContext.request.contextPath}/sys/role/resourcesView.do";
	var dialog = art.dialog({
		id:'resourcesViewDialog',
		lock:true,
		top:'10%'
	});
	$.post(url,{roleId:roleId},function(data){
		dialog.content(data);
	});
}
function delRole(roleId){
	if(roleId == 1){
		alert("超级管理员不能删除...");
		return;
	}
	var url = "${pageContext.request.contextPath}/sys/role/roleDel.do";
	$.post(url,{roleId:roleId},function(data){
//		var data = eval('(' + data + ')');
		if(data.success){
			art.dialog({content:data.msg,resize:true,time:2,icon:'succeed',ok:function(){this.close()}});
			$('#RoleTable').DataTable().draw() ;		//重新刷新数据表格
		}
	})
}

function editRole(roleId){
	var url = "${pageContext.request.contextPath}/sys/role/roleEditPage.do";
	var dialog = art.dialog({
		id:'editRoleDialog',
		lock:true,
		top:'10%'
	});
	$.post(url,{roleId:roleId},function(data){
		dialog.content(data);
	});
}

function addRole(){
	var url = "${pageContext.request.contextPath}/sys/role/roleAddPage.do";
	var dialog = art.dialog({
		id:'addRoleDialog',
		lock:true,
		top:'10%'
	});
	$.post(url,function(data){
		dialog.content(data);
	});
}
</script>
<div class="breadcrumbs">
	<script type="text/javascript">
		try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
	</script>
	<ul class="breadcrumb">
		<li>
			<i class="ace-icon fa fa-home home-icon"></i>
			<a href="#">首页</a>
		</li>
		<li class="active">角色列表</li>
	</ul><!-- /.breadcrumb -->
	<div class="nav-search" id="nav-search">
		<form class="form-search">
			<span class="input-icon">
				<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
				<i class="ace-icon fa fa-search nav-search-icon"></i>
			</span>
		</form>
	</div><!-- /.nav-search -->
</div>
<div class="page-content">
	<div class="row">
		<div class="col-sm-12">
			<shiro:hasPermission name="sys:role:add">
			<button class="btn btn-white btn-default btn-round btn-sm" onclick="addRole()">
				<i class="ace-icon fa fa-pencil-square-o red2"></i>
				新增
			</button>
			</shiro:hasPermission>
			<table class="table row-border cell-border table-hover table-striped" id="RoleTable">
				<!-- <table class="table table-striped table-bordered table-hover" id="RoleTable"> -->
					<thead>
						<tr>
						<th class="center">
							<input type="checkbox" class="ace"/> <span class="lbl"></span>
						</th>
						<th>角色名</th>
						<th>备注</th>
						<th>显示顺序</th>
						<th>操作</th>
						</tr>
					</thead>
				</table>
		</div>
	</div>
</div>